<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>task type page</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<!-- Add by Kravis Liu 2014.09.22 -->
		<link rel="stylesheet" href="/css/base.css" />
		<link rel="stylesheet" href="/css/list.css" />
		<link rel="stylesheet" media="screen" href="/css/validate.css">
		<script src="/js/av-mini.js"></script>
		<script src="/js/av.js"></script>
		<script src="/js/jquery-1.11.1.min.js"></script>
		<script src="/js/jqueryValidation/jquery.validate.min.js"></script>	
		<script src="/js/jqueryValidation/additional-methods.js"></script>		
		<script type="text/javascript">

			$(document).ready(function(){
			        
			        $("#createInstallPackForm").validate({
					rules: {
						versionCode: {
							required: true
						},
						description: {
							required: true
						},
						versionType: {
						    required: true
						},
						activated: {
						    required: true,
							digits: true
						},
						installFile: {
							required: true,
							extension:'apk,ipa,xap'
						}
		                       
					},
					messages: {
						versionCode: {
							required: "版本号不能为空！"
						},
						description: {
							required: "版本描述不能为空！"
						},
						versionType: {
						        required: "客户端类型不能为空！"
						},
						activated: {
						        required: "使用状态不能为空！",
						        digits: "请输入数字！"
						},
						installFile: {
						        required: "安装文件不能为空！",
								extension: "文件类型不正确！"
						}
					},
					submitHandler:function(form){
								
		                            form.submit();
		                        }
				});
			});
			
			function addInstallPack(){
				var type = $("#taskType").val();
				if(type == ""){
					alert("任务类别不能为空！");
					return;
				} else {
					$("#createTaskTypeForm").submit();
				}
												
			}
		
			function changeActivated(id){
				if(confirm("是否修改客户端升级包状态？")){
					var activatedHidden = $('#activatedHidden').val();					
					var activatedValue = 0;
					var activatedText = "未使用";
					if(activatedHidden == 0){
						activatedValue = 1;
						activatedText = "使用中";
					}
					$.ajax({
					   type: "POST",
					   url: "/app/changeInstallPackActivated",
					   data: "installPackId="+id + "&activatedValue=" + activatedValue,
					   success: function(msg){						 
						 if(msg == "success"){						
							$("#"+id).find("td[name='activated']").text(activatedText);
							$("#"+id).find("input[name='activatedHidden']").val(activatedValue);
						 } else {
							alert( msg );
						 }
						 
					   }
					});	
				}
			}
			
			function deleteInstallPack(id){
				if(confirm("是否删除客户端升级包？")){
					$.ajax({
					   type: "POST",
					   url: "/app/deleteInstallPack",
					   data: "installPackId="+id,
					   success: function(msg){						 
						 if(msg == "success"){						
							$("#"+id).hide();
						 } else {
							alert( msg );
						 }
						 
					   }
					});				
				}

			}
					
		</script>
	</head>
	
	<body>
		<div id="page">
			<div id="header">
				<h4>后台管理</h4>
			</div>
			<div align="center">
			<form enctype="multipart/form-data" method="post" id="createInstallPackForm" action="/app/createInstallPack">
			 版本号：<input id="versionCode" name="versionCode" value="" type="text"/></p>
			 版本描述：<input id="description" name="description" value="" type="text"/></p>
			 客户端类型：<select name="versionType" id="versionType">
						<option value="Android">Android</option>
						<option value="IOS">IOS</option>
						<option value="WindowsPhone">WindowsPhone</option>
					   </select></p>
			 使用状态：<select name="activated" id="activated">
						<option value="1">使用中</option>
						<option value="0">未使用</option>
					   </select></p>					   
			 安装文件：<input type="file" id="installFile" name="installFile"></p>
					   <button name="button" class="change" onClick="addInstallPack();">添加</button>
			 </form>
			 </div>
			 <div id="content_div">
				<table width="98%" border="1" cellpadding="0" cellspacing="0" style="table-layout:fixed; word-break:break-all">
					<thead>
					        <tr>
							<td height="11" width="20%" align="center">版本号</td>
							<td height="11" width="20%" align="center">版本描述</td>
							<td height="11" width="20%" align="center">客户端类型</td>
							<td height="11" width="20%" align="center">使用状态</td>
							<td height="11" width="20%" align="center">操作</td>
						</tr>
				        </thead>
					
					<tbody id="add_point">
						
						<% if(InstallPacks){ %>
						<% InstallPacks.forEach(function (installPack){ %>
						<tr id="<%= installPack.id%>">
							<td height='11' width='20%' align='center' name="versionCode"><%= installPack.get('versionCode')%></td>
							<td height='11' width='20%' align='center' name="description"><%= installPack.get('description')%></td>
							<td height='11' width='20%' align='center' name="versionType"><%= installPack.get('versionType')%></td>
							<% if(installPack.get('activated') == '0'){%>
							<td height='11' width='20%' align='center' name="activated">未使用</td>
							<input id="activatedHidden" name="activatedHidden" value="0" type="hidden"/></p>
							<%}%>
							<% if(installPack.get('activated') == '1'){%>
							<td height='11' width='20%' align='center' name="activated">使用中</td>
							<input id="activatedHidden" name="activatedHidden" value="1" type="hidden"/></p>
							<%}%>							
							<td height='11' width='20%' align='center'>
								<a href='<%= installPack.get("installFile").url()%>' >下载</a>
								<a href='javascript:void(0)' onClick='changeActivated("<%= installPack.id%>");' >切换状态</a>
								<a href='javascript:void(0)' onClick='deleteInstallPack("<%= installPack.id%>");'>删除</a>
								
							</td>
						</tr>
						<% })} %>  			
					</tbody>			
				</table>
			 </div>
			 
			 <div id="footer">
				<a style="float:right;margin:5px" href="/logout">退出</a>
				<a style="float:right;margin:5px" href="/app/index">主页</a>
				<% if(next != 0){ %>
					<a style="float:right;margin:5px" href="/app/installPackList?page=<%=next%>">下一页</a>
				<%}%>					
				<% if(previous >= 0){ %>
					<a style="float:right;margin:5px" href="/app/installPackList?page=<%=previous%>">上一页</a>
				<%}%>				
			</div>
		 </div>
	</body>
</html>
